package stack;

import java.util.Stack;

// 每日温度
public class leetcode739 {
    public static void main(String[] args) {
        int[] temperature = {73,74,75,71,69,72,76,73};
        for(int i : dailyTemperature(temperature)){
            System.out.print(i+" ");
        }
    }

    public static int[] dailyTemperature(int[] nums){
        int[] result = new int[nums.length];
        Stack<Integer> stack = new Stack<Integer>();
        stack.push(0);
        for(int i = 1; i < nums.length; i++){
            while(!stack.isEmpty() && nums[i] > nums[stack.peek()]){
                int n = stack.pop();
                result[n] = i - n;
            }
            stack.push(i);
        }
        return result;
    }
}
